/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.dao.jpa;

import com.supinfo.youfood.dao.TableRestoDao;
import com.supinfo.youfood.entity.TableResto;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author TaKeO
 */
@Stateless
public class JpaTableRestoDao implements TableRestoDao{
    
    @PersistenceContext
    private EntityManager em;

    @Override
    public TableResto addTableResto(TableResto table) {
        em.persist(table);
        return table;
    }

    @Override
    public List<TableResto> getAllTableResto() {
        String query = "SELECT t "+
                        "FROM TableResto t";
        Query result = em.createQuery(query);
        return (List<TableResto>)result.getResultList();
    }

    @Override
    public TableResto findTableById(Long id) {
        return em.find(TableResto.class, id);
    }

    @Override
    public void updateTableResto(TableResto table) {
        em.merge(table);
    }
    
}
